#ifndef QUATERNIONMATH_H
#define QUATERNIONMATH_H

#include <math.h>
#include <qquaternion.h>
#include <QVector3D>


class quaternionMath
{
public:
    quaternionMath();
    ~quaternionMath();

   typedef struct quat
    {
        double w, x, y, z;
    }quat;

   typedef struct quatAbbreviations
    {
        double q0;
        QVector3D qv;
    }quatAbbreviations;

    typedef  union QUAT_TYPE // 四元数
    {
            double M[4];
            quat quat;
            quatAbbreviations quat1; //未用
    } QUAT, *QUAT_PTR;
private:



   void QuatCreate(QUAT_PTR q, QVector3D &v, double theta);// 创建用于旋转的四元数q, v必须为单位向量
   void QuatGetVectorAndTheta(QUAT_PTR q, QVector3D &v, double *theta);
   void QuatAdd(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR qsum);
   void QuatSub(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR qdiff);
   void QuatConjugate(QUAT_PTR q, QUAT_PTR qconj);// 求共轭
   void QuatScale(QUAT_PTR q, double scale, QUAT_PTR qs);
   double QuatNorm(QUAT_PTR q);
   double QuatNorm2(QUAT_PTR q);
   void QuatNormalize(QUAT_PTR q, QUAT_PTR qn);
   void QuatUnitInverse(QUAT_PTR q, QUAT_PTR qi);// 单位四元数的逆，等于求共轭
   void QuatInverse(QUAT_PTR q, QUAT_PTR qi); // 非单位四元数的逆

   void QuatMul3(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR q3, QUAT_PTR qprod);// 三个四元数相乘，用于做旋转变换
   void QuatMul(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR qprod);
};

#endif // QUATERNIONMATH_H
